{% extends "upload/dataset_upload_base.html" %}
{% load i18n %}
{% load static %}
{% load pinax_ratings_tags %}
{% load bootstrap_tags %}
{% load pagination_tags %}
{% load base_tags %}
{% load guardian_tags %}
{% load client_lib_tags %}

{% block title %} {% trans "Replace Dataset"  %} - {{ block.super }}  {% endblock %}

{% block body_class %}layers upload{% endblock %}


{% block head %}

{{ block.super }}
{% endblock %}

{% block body_outer %}
<div class="page-header">
  <a href="{% dataset_list_url %}" class="btn btn-primary pull-right" style="margin-left: 3px;">{% trans "Explore Datasets" %}</a>
  <a href="{{ resource.get_absolute_url }}"  class="btn btn-primary pull-right" style="margin-left: 3px;">{% trans "Return to Dataset" %}</a>
  <h2 class="page-title">{% trans "Replace Dataset" %} <small><a href="{{ resource.get_absolute_url }}">{{ resource.title }}</a><small></h2>
</div>
<div class="row">
  <div class="col-md-8">
    {% block additional_info %}{% endblock %}

    {% if errors %}
    <div id="errors" class="alert alert-danger">
      {% for error in errors %}
      <p>{{ error }}</p>
      {% endfor %}
    </div>
    {% endif %}

    <div id="upload-status"></div>

    <section id="drop-zone">
      <h3><i class="fa fa-cloud-upload"></i><br />{% trans "Drop files here" %}</h3>
    </section>

    <p>{% trans " or select them one by one:" %}</p>

    <form id="file-uploader" method="post" enctype="multipart/form-data">
      <!-- UI change to hide the list of previously uploaded files from the user -->
      <input type="file" id="file-input" style="display: none;" multiple>
      <input class="btn btn-default" type="button" value="{% trans "Choose Files" %}" onclick="document.getElementById('file-input').click();">
    </form>

    <section class="widget">
      <ul id="global-errors"></ul>
      <h4>{% trans "Files to be uploaded" %}</h4>
      <div id="file-queue"></div>
      <div class="checkbox" style="display:none;" id="metadata_uploaded_preserve_check">
          {% trans "Preserve Metadata XML" %} <input type="checkbox" name="metadata_uploaded_preserve" id="id_metadata_uploaded_preserve"/>
      </div>
    </section>

    <section class="charset">
      <p>{% trans "Select the charset or leave default" %}</p>
      <select id="charset">
        {% for charset in charsets %}
        {% if charset.0 == 'UTF-8' %}
        <option selected='selected' value={{ charset.0 }}>{{ charset.1 }}</option>
        {% else %}
        <option value={{ charset.0 }}>{{ charset.1 }}</option>
        {% endif %}
        {% endfor %}
      </select>
    </section>

    <section>
      <a href="#" id="clear-button" class="btn btn-default">{% trans "Clear" %}</a>
      <a href="#" id="upload-button" class="btn btn-primary">{% trans "Replace Dataset" %}</a>
    </section>
  </div>

  {% if GEOSERVER_BASE_URL %}
    {% get_obj_perms request.user for resource.dataset as "dataset_perms" %}
  {% endif %}

</div>
{% endblock %}


{% block extra_script %}
{{ block.super }}
<script data-main="{% static 'geonode/js/upload/main.js' %}"
  src="{% static 'lib/js/require.js' %}">
</script>
<script type="text/javascript">
{% autoescape off %}

  csrf_token =  "{{ csrf_token }}",
  form_target = "{% url "dataset_replace" resource.service_typename %}",
  time_enabled = {{ TIME_ENABLED|lower  }},
  mosaic_enabled = {{ MOSAIC_ENABLED|lower  }},
  userLookup = "{% url "account_ajax_lookup" %}"

{% endautoescape %}

</script>
{% endblock extra_script %}
